package com.skytech.chatim.sky.util;

import java.io.File;
import java.util.List;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.net.Uri;
import android.os.Environment;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.widget.Toast;

public class AndroidUtil {
    private static String TAG = AndroidUtil.class.getSimpleName();
    public static void showToast(Context context, String text) {
        Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
    }

    public static void showLongToast(Context context, String text) {
        Toast.makeText(context, text, Toast.LENGTH_LONG).show();
    }

    public static void showToast(Context context, int id) {
        Toast.makeText(context, context.getResources().getString(id),
                Toast.LENGTH_SHORT).show();
    }

    public static void showLongToast(Context context, int id) {
        Toast.makeText(context, context.getResources().getString(id),
                Toast.LENGTH_SHORT).show();
    }

    public static String getFileDir() {
        File file = Environment.getExternalStorageDirectory();
        String skyFileS = file.getPath() + "/skytech";
        File skyFile = new File(skyFileS);
        if (!skyFile.exists()) {
            skyFile.mkdir();
        }
        return skyFileS;
    }

    public static ProgressDialog getProgressDialog(
            Activity activity, String string) {
         ProgressDialog pd = new ProgressDialog(activity);
        pd.setMessage(string);
        pd.setCanceledOnTouchOutside(false);
        pd.show();
        return pd;
    }

    public static boolean notInstallWebex(Context context) {
        final PackageManager packageManager = context.getPackageManager();
        final Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(String.format("wbx://WbxStartMeeting?MK=2222")));
        List<ResolveInfo> list =
                packageManager.queryIntentActivities(intent,
                        PackageManager.MATCH_DEFAULT_ONLY);
        return list.size() == 0;
    }

    public static void closeDialog(Dialog dialog) {
        try {
            dialog.cancel();
        } catch (Exception e) {
            Log.d(TAG," closeDialog " +e);
        }
        
    }

    public static void startLink(Activity activity, String link) {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(link));
        activity.startActivity(intent);
    }
    
    public static boolean  isTestService(Activity activity) {
    	String imei =((TelephonyManager) activity.getSystemService(activity.TELEPHONY_SERVICE)).getDeviceId();
    	Log.d(TAG," imei " +imei);
    	return imei.equals("99000522351077") ||  imei.equals("866278011642274") ;
    }

}
